import React, { PureComponent } from 'react';
import { connect } from 'dva';
import { formatMessage, FormattedMessage } from 'umi-plugin-react/locale';
import {
  Form,
  Input,
  DatePicker,
  Select,
  Button,
  Card,
  InputNumber,
  Radio,
  Icon,
  Tooltip,
} from 'antd';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';

const FormItem = Form.Item;
const { Option } = Select;
const { RangePicker } = DatePicker;
const { TextArea } = Input;

@connect(({ loading }) => ({
  submitting: loading.effects['form/submitRegularForm'],
}))
@Form.create()
class BasicForms extends PureComponent {
  handleSubmit = e => {
    const { dispatch, form } = this.props;
    e.preventDefault();
    form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        dispatch({
          type: 'admin/addAdmin',
          payload: values,
        });
      }
    });
  };

  render() {
    const { submitting } = this.props;
    const {
      form: { getFieldDecorator},
    } = this.props;

    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 12 },
        md: { span: 10 },
      },
    };

    const submitFormLayout = {
      wrapperCol: {
        xs: { span: 24, offset: 0 },
        sm: { span: 10, offset: 7 },
      },
    };

    return (
      <PageHeaderWrapper
        title='添加管理员'
        content='添加管理员，并分配权限'
      >
        <Card bordered={false}>
          <Form onSubmit={this.handleSubmit} hideRequiredMark style={{ marginTop: 8 }}>
            <FormItem {...formItemLayout} label='登录帐号'>
              {getFieldDecorator('name', {
                rules: [{ required: true, message: '请输入登录帐号' }]
              })(
                <Input placeholder='输入帐号，英文加数字' />
              )}
            </FormItem>
            <FormItem {...formItemLayout} label='密码'>
              {getFieldDecorator('password', {
                rules: [{ required: true, message: '请输入密码' }]

              })(
                <Input.Password placeholder='请输入密码' type='password' allowClear />
              )}

            </FormItem>
            <FormItem {...formItemLayout} label='真实姓名'>
              {getFieldDecorator('realname', {
                rules: [{ required: true, message: '请输入真实姓名' }]

              })(
                <Input placeholder='真实姓名' allowClear />
              )}

            </FormItem>
            <FormItem {...formItemLayout} label='联系电话'>
              {getFieldDecorator('phone', {
                rules: [{ required: true, message: '请输入联系电话' }]
              })(
                <Input placeholder='联系电话' type='number' allowClear />
              )}
            </FormItem>
            <FormItem {...formItemLayout} label='职能部门'>
              {getFieldDecorator('department',{
                initialValue: 0
              })(
                <Radio.Group>
                  <Radio value={0}>
                    管理
                  </Radio>
                  <Radio value={1}>
                    运营
                  </Radio>
                  <Radio value={2}>
                    微信公众号
                  </Radio>
                </Radio.Group>
              )}

            </FormItem>
            <FormItem {...formItemLayout} label='状态'>
              {getFieldDecorator('status',{
                initialValue: 0
              })(
                <Radio.Group>
                  <Radio value={0}>
                    激活
                  </Radio>
                  <Radio value={1}>
                    冻结
                  </Radio>

                </Radio.Group>
              )}

            </FormItem>

            <FormItem {...submitFormLayout} style={{ marginTop: 32 }}>
              <Button type="primary" htmlType="submit" loading={submitting}>
                <FormattedMessage id="form.submit" />
              </Button>
              <Button style={{ marginLeft: 8 }}>
                <FormattedMessage id="form.reset" />
              </Button>
            </FormItem>
          </Form>
        </Card>
      </PageHeaderWrapper>
    );
  }
}

export default BasicForms;
